package org.jeecg.modules.util;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;

import java.io.IOException;

public class Text2PdfUtil {
    public static String readPDF(String filename){
        StringBuilder result = new StringBuilder();
        try {
            PdfReader reader = new PdfReader(filename);
            int countPage = reader.getNumberOfPages();
            for(int i=1;i<=countPage;i++){
                result.append(PdfTextExtractor.getTextFromPage(reader, i));
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result.toString();
    }

    public static void main(String[] args) {
        String filename = "E:\\1.pdf";
        System.out.println(readPDF(filename));
    }
}
